import { Injectable } from '@angular/core';

@Injectable()
export class UtilsService {

    public static roundUp(value: number): number {
        return Math.round(value * 10) / 10;
    }

    public static getCompanyUrlFriendlyName(company: any): string {
        return this.getUrlFriendlyName(company.companyName) + '_' + company.id;
    }

    public static getUrlFriendlyName(input: string): string {
        return input.replace(/[?/&=#,]/g, '-').replace(/[. ]/g, '_');
    }

    public static aggregateDataByRiskCluster(riskClusters: Array<any>, data: Array<any>, categoryName: string = 'value'): Array<any> {
        return data.map((clusterData, index) => {
            let obj = {
                riskCluster: riskClusters[index].name,
            };
            obj[categoryName] = clusterData.yValue;

            return obj;
        });
    }
}